﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp9
{
    class Program
    {
        static NPC nPC;
        static PlayYou you;
        static int CiShu = 0; //用来计算对战次数 并 赋初始值
       
        enum HeroName 
        { 
          刘备=1,
          曹操,
          孙权
        }
        


        static void Main(string[] args)
        {
            Game();
        }

        public  static void Game()
        {
            Console.WriteLine("----------欢迎进入游戏世界----------");
            Console.WriteLine("*************猜拳，开始********");
            Console.WriteLine("出拳规则：1.石头 2.剪刀 3.布");
            Console.WriteLine("请选择对方角色<1.刘备 2.曹操 3.孙权>");
            int key = int.Parse(Console.ReadLine());
            if (key>0 && key<=3)   //此if 用来判断是否在人机的范围内
            {
                HeroName heroName = (HeroName)key; //将输入的数 转换成对应的枚举类型的枚举值
                string NPCName = heroName.ToString();//将对应的枚举值转换成 string
                nPC = new NPC(NPCName);          //将转换后的string 传到NPC类当中
                Console.WriteLine("请输入您的姓名：");
                string PlayFamily = Console.ReadLine();
                you = new PlayYou(PlayFamily);
                Console.WriteLine("{0} VS {1}", you.Name, nPC.Name);
                Console.WriteLine("开始游戏吗？<y/n>");
            CxPlay: string YesORNo = Console.ReadLine();
                you.FenShu = 0; //分数初始化
                nPC.FenShu = 0;//分数初始化
                CiShu = 0;     //对战次数初始化
            XunHuan: switch (YesORNo)
                {
                    case "y":           //开始游戏
                        you.ChuQuan();  //输出玩家
                        nPC.ChuQuan();  //输出人机
                        CaiPan();       //判断
                        Console.WriteLine("是否继续下一局？（y/n）");
                        string yn = Console.ReadLine();
                        switch (yn)
                        {
                            case "y":             //开始游戏
                                goto XunHuan;     //循环继续游戏

                            case "n":
                                PrintJieGuo();  //结束游戏 并打印结果
                                Console.WriteLine("亲爱的！要再玩一把吗？（y/n）");
                                goto CxPlay;

                                //  goto XunHuan;     //清掉所有数据后  继续走循环开始游戏
                                break;
                            default:
                                Console.WriteLine("请睁大你的狗眼！输入：y 或者 n。即将返回游戏首页");
                                Game();
                                break;
                        }
                        break;
                    case "n":
                        Console.WriteLine("程序结束！拜拜！");  //结束游戏 并打印结果                  
                        break;
                    default:
                        Console.WriteLine("请睁大你的狗眼！输入：y 或者 n。即将返回游戏首页");
                        Game();
                        break;
                }
            }
            else
            {
                Console.WriteLine("输入错误！！");
                Game();
            }


        }

        private static void PrintJieGuo()//打印结果
        {
            Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
            Console.WriteLine("        {0} VS {1}",you.Name,nPC.Name);
            Console.WriteLine("        对战次数:{0}", CiShu );
            Console.WriteLine("                                        ");
            Console.WriteLine("        姓名: 得分:");
            Console.WriteLine("        {0},   {1}", you.Name,you.FenShu );
            Console.WriteLine("        {0},   {1}", nPC.Name,nPC.FenShu );
            Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
        }

        //裁判  判断输赢
        public static void CaiPan() 
        {
            CiShu++;       //只要进入游戏，那么对战次数就++

            if (you.STJDB==nPC.STJDB)
            {
                Console.WriteLine("真晦气！和局");
            }
            //1石头 2剪刀 3布
            else if (you.STJDB==1&&nPC.STJDB==2 || you.STJDB==2 && nPC.STJDB==3 || you.STJDB==3 && nPC.STJDB==1)
            {
                Console.WriteLine("真棒！！{0}赢了",you.Name);
                you.FenShu++;
            }
            else
            {
                Console.WriteLine("笨蛋{0}！{1}输了", you.Name,you.Name);
                nPC.FenShu++;
            }
       
        }
       


    }
}
